/**
 *
 */
Ext.define('vacake.view.ProductAccess', {
    extend: 'Ext.form.Panel',
    xtype: 'productAccess',
    requires: [
        'Ext.form.FieldSet'
    ],
    config: {
        style:'background:#EEEAE0',
        scrollable: {
            direction: 'vertical',
            directionLock: false
        },
        layout: 'vbox',
        items: [
            {
                docked: 'top',
                xtype: 'titlebar',
                title: '产品评价',
                items: [
                    {
                        text: '返回',
                        ui: 'action-back',
                        handler: function () {
                            var backid = Ext.Viewport.getInnerItems().length - 2;
                            Ext.Viewport.remove(this.up('productAccess'), true);
                            Ext.Viewport.setActiveItem(backid);
                        }
                    }
                ]
            },
            {
                xtype: 'fieldset',
                items: [
                    {
                        xtype: 'selectfield',
                        name: 'grade',
                        id: 'grade',
                        label: '评价分:',
                        options: [
                            {text: '1', value: '1'},
                            {text: '2', value: '2'},
                            {text: '3', value: '3'},
                            {text: '4', value: '4'},
                            {text: '5', value: '5'}
                        ]
                    },
                    {
                        xtype: 'textareafield',
                        name: 'messages',
                        id: 'messages',
                        label: '评价内容:',
                        autoCapitalize: true
                    },
                    {
                        xtype: 'hiddenfield',
                        name: 'cuid',
                        id: 'form_cuid'
                    },
                    {
                        xtype: 'hiddenfield',
                        name: 'cpid',
                        id: 'form_cpid'
                    },
                    {
                        xtype: 'hiddenfield',
                        name: 'coid',
                        id: 'form_coid'
                    },
                    {
                        xtype: 'button',
                        ui: 'confirm',
                        text: '评价',
                        id: 'assess',
                        listeners: {
                            tap: function () {
                                Ext.Viewport.mask({
                                    xtype: 'loadmask',
                                    message: '提交中...'
                                });
                                if(Ext.getCmp('messages').getValue()==''){
                                    Ext.Viewport.unmask();
                                    cordova.exec(function(message){}, function(error){}, "Messages", "showMsg", ['请添加评价的内容！']);
//                                    Ext.Msg.alert('请添加评价的内容！');
                                    return false;
                                }
                                this.up('productAccess').submit({
                                    url: Global.api_url + '/cloud/1/assess_product_add',
                                    method: 'POST',
                                    scope: this,
                                    success: function (from, result) {
                                        Ext.Viewport.unmask();
                                        cordova.exec(function(message){}, function(error){}, "Messages", "showMsg", [result.Variables.Message.messagestr]);
//                                        Ext.Msg.alert(result.Variables.Message.messagestr);
                                        if (result.Variables.Result.code == 0) {
                                            Ext.Viewport.remove(this.up('productAccess'), true);
                                        }
                                    },
                                    failure: function () {
                                        Ext.Viewport.unmask();
                                        //请求失败时执行操作
                                        cordova.exec(function(message){}, function(error){}, "Messages", "showMsg", ['请求失败,服务器维护中...']);
//                                        Ext.Msg.alert('请求失败', '服务器维护中....');
                                    }
                                });
                            }
                        }
                    }
                ]
            }
        ],
        listeners: {
            painted: function () {
                var accessItem = Ext.decode(window.localStorage.getItem('accessItem'));
                Ext.getCmp('form_cuid').setValue(accessItem.cuid)
                Ext.getCmp('form_cpid').setValue(accessItem.cpid)
                Ext.getCmp('form_coid').setValue(accessItem.coid)
                Ext.getCmp('grade').setValue(3);
            },
            back: function () {
                var backid = Ext.Viewport.getInnerItems().length - 2;
                Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
                Ext.Viewport.setActiveItem(backid);
            }
        }
    }

});

